package model

import (
	"context"

	"github.com/Masterminds/squirrel"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

var _ AwJobCategoriesModel = (*customAwJobCategoriesModel)(nil)

type (
	// AwJobCategoriesModel is an interface to be customized, add more methods here,
	// and implement the added methods in customAwJobCategoriesModel.
	AwJobCategoriesModel interface {
		awJobCategoriesModel
		withSession(session sqlx.Session) AwJobCategoriesModel
		GetAll(ctx context.Context, session sqlx.Session) ([]*AwJobCategories, error)
	}

	customAwJobCategoriesModel struct {
		*defaultAwJobCategoriesModel
	}
)

// NewAwJobCategoriesModel returns a model for the database table.
func NewAwJobCategoriesModel(conn sqlx.SqlConn) AwJobCategoriesModel {
	return &customAwJobCategoriesModel{
		defaultAwJobCategoriesModel: newAwJobCategoriesModel(conn),
	}
}

func (m *customAwJobCategoriesModel) withSession(session sqlx.Session) AwJobCategoriesModel {
	return NewAwJobCategoriesModel(sqlx.NewSqlConnFromSession(session))
}

func (m *customAwJobCategoriesModel) GetAll(ctx context.Context, session sqlx.Session) ([]*AwJobCategories, error) {
	query, args, err := squirrel.Select("*").From(m.table).ToSql()
	if err != nil {
		return nil, err
	}
	var jobCates []*AwJobCategories
	if session != nil {
		err = session.QueryRowsPartialCtx(ctx, &jobCates, query, args...)
	} else {
		err = m.conn.QueryRowsPartialCtx(ctx, &jobCates, query, args...)
	}
	return jobCates, err
}
